﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class XMLHttpRequest_xmlhttprequest : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int intValidateID = Int32.Parse(this.Page.Request.Params["ValidateID"].ToString());
            string strValidateValue = this.Page.Request.Params["ValidateValue"].ToString();

            this.RequestValidate(intValidateID, strValidateValue);
        }
    }

    protected void RequestValidate(int ValidateID, string ValidateValue)
    {
        StringBuilder strReturn = new StringBuilder();

        if (ValidateID == 1)//检查输入的商品号或商品名是否存在
        {
            ClsPropertyDAL cls_Property = new ClsPropertyDAL();

            string strUserID = cls_Property.SetOrGetUserID;
            string strCusNo = (string)Session["CustomerNo"];

            if (strUserID != "" && strCusNo != null && strCusNo != "")
            {
                ClsProductDataDAL cls_ProductData = new ClsProductDataDAL();
                DataSet dst = cls_ProductData.GetProductDatas(ValidateValue, 1, strCusNo, strUserID);

                if (dst != null && dst.Tables[0].Rows.Count > 0)
                {
                    strReturn.Append(dst.Tables[0].Rows[0][0].ToString() + "|");
                    strReturn.Append(dst.Tables[0].Rows[0][1].ToString() + "|");
                    strReturn.Append(dst.Tables[0].Rows[0][2].ToString() + "|");
                    strReturn.Append(dst.Tables[0].Rows[0][3].ToString() + "|");
                    strReturn.Append(dst.Tables[0].Rows[0][4].ToString());

                    this.Page.Response.Write(strReturn.ToString());
                }
                else
                {
                    this.Page.Response.Write("-1");
                }
            }
            else
            {
                this.Page.Response.Write("-1");
            }
        }
        else if (ValidateID == 2)////检查输入的客户编号或客户名是否存在
        {
            ClsPropertyDAL cls_PropertyDAL = new ClsPropertyDAL();
            ClsProvideDAL cls_Provide = new ClsProvideDAL();
            string strCurUserId = cls_PropertyDAL.SetOrGetUserID;
            DataSet dst = cls_Provide.SearchProvideSets(strCurUserId,ValidateValue, 0, 0);

            if (dst != null && dst.Tables[0].Rows.Count > 0)
            {
                strReturn.Append(dst.Tables[0].Rows[0][1].ToString() + "|");
                strReturn.Append(dst.Tables[0].Rows[0][30].ToString() + "|");
                strReturn.Append(dst.Tables[0].Rows[0][6].ToString() + "|");
                strReturn.Append(dst.Tables[0].Rows[0][8].ToString() + "|");
                strReturn.Append(dst.Tables[0].Rows[0][11].ToString() + "|");
                strReturn.Append(dst.Tables[0].Rows[0][19].ToString() + "|");
                strReturn.Append(dst.Tables[0].Rows[0][14].ToString() + "|");
                strReturn.Append(dst.Tables[0].Rows[0][17].ToString() + "|");
                strReturn.Append(dst.Tables[0].Rows[0][50].ToString());

                this.Page.Response.Write(strReturn.ToString());
            }
            else
            {
                this.Page.Response.Write("-1");
            }
        }

        this.Page.Response.End();
    }
}
